package org.glut.backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.glut.backend.domain.Actor;
import org.glut.backend.service.IActorService;
import org.glut.backend.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  前端控制器
 *
 * @author wubinbin
 * @since 2025-08-02 14:04
 */
@RestController
@Slf4j

public class ActorController {
  @Autowired
  private IActorService actorService;

  @Autowired
  RedisUtil redisUtil;

    @PostMapping("/public/actor/actorquery")
    public ResponseEntity<List<Object>> actorquery(@RequestBody  Actor condition) {
    log.info("电影主演查询条件{}",condition);
    QueryWrapper<Actor> actorQueryWrapper = new QueryWrapper<>(Actor.class);
    actorQueryWrapper.eq("actortype",condition.getActortype());
    String key="actor:query:"+condition.getActortype();
    List<Object> actorList=null;

    if(!redisUtil.hasKey(key)){
       List _actorList=actorService.list(actorQueryWrapper);
       if(!CollectionUtils.isEmpty(_actorList)){
         //缓存
         redisUtil.lSet(key,_actorList);
         return ResponseEntity.ok(_actorList);
       }
    }else{
      actorList = redisUtil.lGet(key,0,-1);
    }
      return ResponseEntity.ok(actorList);
    }

}
